package com.arvin.controller;

import com.arvin.pojo.NoticeFile;
import com.arvin.pojo.Result;
import com.arvin.utils.AliOSSUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@RestController
@Tag(name = "免试相关接口",description = "免试相关接口")
@Slf4j
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    /**
     * 报名照片上传
     * @param stuImage
     * @return
     */
    @PostMapping("/student/signup/upload")
    @Operation(summary = "文件上传",description = "文件上传")
    public Result updata(MultipartFile stuImage){
        log.info("内容文件{}",stuImage);
        try {
            String url = aliOSSUtils.upload(stuImage);
            return Result.success(url);
        } catch (IOException e) {
            log.info("图片上传失败{}",e);
        }
        return Result.success();
    }

    /**
     * 公告文件上传
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("/admin/upload")
    public Result<NoticeFile> upload(MultipartFile file) throws IOException {
        String url = aliOSSUtils.upload(file);
        String name = file.getOriginalFilename();
        log.info(name + "," + url);
        return Result.success(new NoticeFile(name,url));
    }
}
